
//
//  NewsReleaseEditView.m
//  yameishe3
//
//  Created by pro on 2017/3/7.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "NewsReleaseEditView.h"
#import "JSONKit.h"
@interface NewsReleaseEditView ()
{
    IBOutletCollection(UIButton)NSMutableArray * _contentTypeBtnArray;
    __weak IBOutlet UITextField *_titleTF;
    __weak IBOutlet UITextField *_externalLinksTF;
    __weak IBOutlet UITextField *_keywordTF;
    __weak IBOutlet UITextView *_remarksTV;
    __weak IBOutlet UIButton *_agreeBtn;
    __weak IBOutlet UIButton *_agreementBtn;
    __weak IBOutlet UIButton *_startBtn;
    __weak IBOutlet UIButton *_stopBtn;
    
    UIView *_agreementView;
    NSNumber *_contentType;
    BOOL agree;
}
@end

@implementation NewsReleaseEditView

-(void)awakeFromNib
{
    [super awakeFromNib];
    _contentType = [NSNumber numberWithInt:0];
    agree = NO;

    NSString *textFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FaBuXieYi" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@",textFileContents);
    NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FaBuXieYi" ofType:@"txt"]];
    NSDictionary *dic = [data objectFromJSONData];
    [self setAgreementView];
    
}

-(void)setAgreementView
{
    _agreementView = [[[NSBundle mainBundle]loadNibNamed:@"space" owner:self options:nil] objectAtIndex:1];
    _agreementView.alpha = 0;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:_agreementView];
    UIButton *cancleBtn = [_agreementView viewWithTag:102];
    [cancleBtn addTarget:self action:@selector(hideCallView) forControlEvents:UIControlEventTouchUpInside];
    UIView *bgView = [_agreementView viewWithTag:1000];
    bgView.layer.cornerRadius=4.5;
}

-(IBAction)onTouchShowAgreement:(id)sender
{
    [UIView animateWithDuration:0.35 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        _agreementView.alpha = 1;
        _agreementView.frame = self.viewController.view.bounds;
    } completion:nil];
}

-(IBAction)onTouchContentTypeBtn:(UIButton *)sender
{
    for (UIButton * btn in _contentTypeBtnArray) {
        btn.selected = NO;
    }
    sender.selected = YES;
    _contentType = [NSNumber numberWithInteger:sender.tag];
}

-(IBAction)onTouchAgreeBtn:(UIButton *)sender
{
    sender.selected = !sender.selected;
    agree = sender.selected;
}

-(void)hideCallView
{
    [UIView animateWithDuration:0.35 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        _agreementView.alpha = 0;
    } completion:nil];
}
@end
